﻿using UnityEditor;
using UnityEngine;

namespace ChivalryUnityEditor
{
    /// <summary>
    /// @Author:Teddy
    /// </summary>
    [CustomPropertyDrawer(typeof(FieldLabelAttribute))]
    public class FieldLabelDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            FieldLabelAttribute fieldLabel = attribute as FieldLabelAttribute;
            EditorGUI.PropertyField(position, property, new GUIContent(fieldLabel.Label));
            EditorGUI.EndProperty();
        }
    }

    public class FieldLabelAttribute : PropertyAttribute
    {
        public string Label { get; private set; }

        public FieldLabelAttribute(string label)
        {
            Label = label;
        }
    }
}